package com.zlzxm.sorting.ui.activity

import android.view.View
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager
import androidx.viewbinding.ViewBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.zlzxm.sorting.databinding.AcIndexBinding
import com.zlzxm.sorting.globe.startPage
import com.zlzxm.sorting.ui.adapter.AdapterIndexMenu
import com.zlzxm.sorting.ui.vm.VmIndex
import com.zlzxm.sorting.util.ui.manager.AbsAcBase

/**
 *
 *CREATE BY zlzxm ON 2022/8/20
 *
 */
class AcIndex:AbsAcBase(), OnItemClickListener {

    val binding by lazy {

        AcIndexBinding.inflate(layoutInflater)
    }

    val viewModel by lazy {

        ViewModelProvider(this).get(VmIndex::class.java)
    }

    val adapterIndexMenu = AdapterIndexMenu()

    override fun initBinding(): ViewBinding {

        return binding
    }

    override fun initViewModel() {
    }

    override fun initView() {
//        fullScreenMode()
        binding.rvMenu.layoutManager = GridLayoutManager(this,4)
        binding.rvMenu.adapter = adapterIndexMenu

        binding.llLogin.setOnClickListener{startPage(AcLogin::class.java)}
        binding.llClose.setOnClickListener{ finish() }

        adapterIndexMenu.setOnItemClickListener(this)

    }

    override fun initData() {
        adapterIndexMenu.setNewInstance(viewModel.menuListData)
        viewModel.loadPageData()
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {

        val id = adapterIndexMenu.data[position].id
        when(id){

             1 ->{ startPage(AcSortingByProduct::class.java)}
             2 ->{ startPage(AcSortingByMerchant::class.java)}
             3 ->{ startPage(AcSetting::class.java)}



        }

    }
}